home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / rsxwdk2s.zip / RSXWDK / LIBSRC / WINIO / WMHANDLR.C < prev    next >
C/C++ Source or Header  |  1994-10-17  |  3KB  |  77 lines

  1. /*
  2. WMHANDLR.C
  3. Event (WM_ message) handlers - implementation
  4. Dave Maxey and Andrew Schulman - 1991
  5. originally published in Microsoft Systems Journal, July 1991
  6. */
  7.  
  8. #define NOGDI
  9. #define NOKERNEL
  10. #define STRICT
  11. #include <windows.h>
  12. #include "wmhandlr.h"
  13.  
  14. long        defwmhandler(HWND, UINT, WPARAM, LPARAM);
  15.  
  16. WMHANDLER    wmhandler[WM_USER];
  17.  
  18. /* -----------------------------------------------------------------------  */
  19. /* This is our event processor. It is the dispatcher for the handlers set   */
  20. /* using SetHandler. An Application plugs this function into its        */
  21. /* window, sets handlers for messages, and WndProc handles the rest.        */
  22. /* This window procecedure should never need to be changed!            */
  23. /* -----------------------------------------------------------------------  */
  24. long FAR PASCAL _export WndProc(HWND hWnd, UINT message,
  25.     WPARAM wParam, LPARAM lParam)
  26.     {
  27.     if (message < WM_USER)
  28.     return (*wmhandler[message])(hWnd, message, wParam, lParam);
  29.     else
  30.     return DefWindowProc(hWnd, message, wParam, lParam);
  31.     }
  32.  
  33. /* ---------------------------------------------------------------- */
  34. /* Routines to get and set the message handlers. Setting to NULL    */
  35. /* uninstalls a handler, by setting the handler to the default        */
  36. /* which calls Windows own DefWndProc.                    */
  37. /* ---------------------------------------------------------------- */
  38. WMHANDLER wmhandler_get(UINT message)
  39.     {
  40.     return (message < WM_USER) ? wmhandler[message] : 0;
  41.     }
  42.  
  43. WMHANDLER wmhandler_set(UINT message, WMHANDLER f)
  44.     {
  45.     WMHANDLER oldf;
  46.     if (message < WM_USER)
  47.     {
  48.     oldf = wmhandler[message];
  49.     wmhandler[message] = f ? f : defwmhandler;
  50.     return (oldf ? oldf : defwmhandler);
  51.     }
  52.     else
  53.     return 0;
  54.     }
  55.  
  56. /* ----------------------------------------------------------------------- */
  57. /* This is a default handler so that an application chain on to a previous */
  58. /* handler from their current one without having to worry what was there   */
  59. /* before. All this default handler does is to call DefWindowProc.       */
  60. /* ----------------------------------------------------------------------- */
  61. long defwmhandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  62.     {
  63.     return DefWindowProc(hwnd, message, wParam, lParam);
  64.     }
  65.  
  66. /* -------------------------------------------------------------------    */
  67. /* MUST BE CALLED BEFORE THE APPLICATION WINDOW IS CREATED -        */
  68. /* Just inits the array of handlers to the default..            */
  69. /* -------------------------------------------------------------------    */
  70. void wmhandler_init(void)
  71.     {
  72.     WMHANDLER *pwm;
  73.     int i;
  74.     for (i=0, pwm=wmhandler; i < WM_USER; i++, pwm++)
  75.     *pwm = defwmhandler;
  76.     }
  77.